<!DOCTYPE html>
<html>

<head>
    <title>数据分析报告</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }

        .container {
            border: 1px solid #ddd;
            padding: 20px;
        }

        h1 {
            text-align: center;
            margin-bottom: 30px;
        }

        h2 {
            margin-top: 30px;
            margin-bottom: 20px;
        }

        ul {
            list-style-type: none;
            padding: 0;
            margin-bottom: 20px;
        }

        ul li {
            margin-bottom: 10px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        table th,
        table td {
            padding: 8px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        table th {
            background-color: #f5f5f5;
        }

        .chart-container {
            text-align: center;
            margin-top: 30px;
        }

        /* 添加样式 */
        .select-container {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 50px;
            margin-bottom: 20px;
        }

        .custom-select {
            padding: 8px 16px;
            border-radius: 4px;
            background-color: #f1f1f1;
            border: none;
            font-size: 16px;
            cursor: pointer;
            outline: none;
        }

        .custom-select:hover {
            background-color: #e8e8e8;
        }

        .custom-select:focus {
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
        }

        /* 并排放置年份和月份按钮 */
        .select-container-inline {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
        }

        .select-container-inline select {
            margin-right: 10px;
        }

    </style>

    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.2/dist/echarts.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts-wordcloud@2.1.0/dist/echarts-wordcloud.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
</head>

<body>
<div class="container">
    <h1 style="color:rgb(0, 0, 0) ; font-size:60px"><strong>数据分析报告</strong></h1>

    <div class="section">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong>项目信息：</strong></h2>
        <ul>
            <li><strong>项目名称:</strong> {{.Title}}</li>
            <li>
                <strong>项目链接:</strong>
                <a href="{{.Source}}"
                >{{.Source}}</a
                >
            </li>
        </ul>
    </div>


    <div class="section" id="table1">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong> 各metric（float 类型）数据表</strong></h2>
        <div id="Table">

            <table>
                <thead>
                <tr>
                    <th>Metric</th>
                    <th>Value</th>
                </tr>
                </thead>
                <tbody>
                {{range $MetricKey, $MetricValue := .MapDataOne}}
                <tr>
                    <td>{{$MetricKey}}</td>
                    <td>{{$MetricValue}}</td>
                </tr>
                {{end}}
                </tbody>
            </table>
        </div>

    </div>



    <div class="section" id="active_dates_and_times">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong>active_dates_and_times ：</strong></h2>
        <div id="chartcal">
            <!-- 可视化图表将在这里插入 -->
            <div class="select" style="margin-right:20px; margin-top:20px; position:fixed; right:20px;"></div>
            <div class="item" id="ca" style="width:1200px;height:300px;"></div>
            <script type="text/javascript">
                var container = document.getElementById('ca');
                var chart = echarts.init(container);
                var baseUrl = 'https://oss.x-lab.info/open_digger/github/';
                var repoName = "{{.Title}}";

                var data0 = {{.ActiveDatesAndTimesData}}

                if (data0) {
                    document.getElementById("active_dates_and_times").style.display = "block";
                } else {
                    document.getElementById("active_dates_and_times").style.display = "none";
                }



                $.getJSON(
                    `${baseUrl}${repoName}/active_dates_and_times.json`,
                    data => {
                        const hours = [...Array(24).keys()];
                        const days = [ 'Sun.', 'Sat.', 'Fri.', 'Thu.', 'Wed.', 'Tue.', 'Mon.' ];
                        // sum up all the working hour
                        var values = Object.values(data).reduce((p, c) => {
                            if (p === null) return c;
                            return p.map((v, i) => v + c[i]);
                        }, null);

                        // use log to smooth the data
                        // comment this line if you want to use linear data
                        // values = values.map(v => Math.log(v + 1));

                        // normalized to 0 - 10
                        var max = Math.max(...values);
                        values = values.map(v => Math.ceil(v * 10 / max));

                        var inputData = [];
                        for (var d = 0; d < 7; d++) {
                            for (var h = 0; h < 24; h++) {
                                inputData.push([h, 6 - d, values[d * 24 + h] || '-']);
                            }
                        }

                        option = {
                            title: {
                                text: `Active Dates And Times for ${repoName}`,
                                left: 'center'
                            },
                            grid: {
                                height: '50%',
                                top: '10%'
                            },
                            xAxis: {
                                type: 'category',
                                data: hours,
                                splitArea: {
                                    show: true
                                }
                            },
                            yAxis: {
                                type: 'category',
                                data: days,
                                splitArea: {
                                    show: true
                                }
                            },
                            visualMap: {
                                min: 0,
                                max: 10,
                                calculable: true,
                                orient: 'horizontal',
                                left: 'center',
                                bottom: '15%'
                            },
                            series: [
                                {
                                    type: 'heatmap',
                                    data: inputData,
                                    // label: {
                                    //   show: true
                                    // },
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    },
                                }
                            ]
                        };
                        chart.setOption(option);
                    }
                )
            </script>
        </div>
    </div>



    <div class="section" id="ActivityDetails">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong>activity_details (detail)：</strong></h2>
        <div id="chart1">
            <!-- 可视化图表将在这里插入 -->
            <div class="select" style="margin-right:20px; margin-top:20px; position:fixed; right:20px;"></div>

            <!-- 创建一个并排放置年份和月份按钮的容器 -->
            <div class="select-container-inline">
                <!-- 创建一个居中且美化的下拉菜单用于选择年份 -->
                <div class="select-container">
                    <select id="yearSelect1" class="custom-select">
                        {{range $value := .Years}}
                        <option value="{{$value}}">{{$value}}</option>
                        {{end}}
                    </select>
                </div>

                <!-- 创建一个居中且美化的下拉菜单用于选择月份 -->
                <div class="select-container">
                    <select id="monthSelect1" class="custom-select">
                        <option value="1">January</option>
                        <option value="2">February</option>
                        <option value="3">March</option>
                        <option value="4">April</option>
                        <option value="5">May</option>
                        <option value="6">June</option>
                        <option value="7">July</option>
                        <option value="8">August</option>
                        <option value="9">September</option>
                        <option value="10">October</option>
                        <option value="11">November</option>
                        <option value="12">December</option>
                    </select>
                </div>
            </div>
            <div class="item" id="wordcloud1" style="width:1200px;height:600px;"></div>


            <script>
                // JavaScript 部分代码
                // 获取数据
                var yearMonthData1 = {{
                .ActivityDetailsData
                }};

                if (yearMonthData1) {
                    document.getElementById("ActivityDetails").style.display = "block";
                } else {
                    document.getElementById("ActivityDetails").style.display = "none";
                }




                document.getElementById("yearSelect1").value = {{.InitYear}};
                document.getElementById("monthSelect1").value = {{.InitMonth}};


                // 生成词云图函数
                function generateWordCloud1(year, month) {
                    // 根据年份和月份获取相应的词频数据
                    var selectedData1 = [];
                    for (var i = 0; i < yearMonthData1.length; i++) {
                        if (yearMonthData1[i].Year === year && yearMonthData1[i].Month === month) {
                            selectedData1 = yearMonthData1[i].Data;
                            break;
                        }
                    }

                    // 将词频数据转换为 ECharts 所需的格式
                    var chartData1 = selectedData1.map(function (item) {
                        return {
                            name: item.Name,
                            value: item.Value
                        };
                    });

                    // 配置词云图的选项
                    var option1 = {
                        series: [{
                            type: 'wordCloud',
                            data: chartData1,
                            rotationRange: [-45, 0, 45, 90],
                            textStyle: {
                                normal: {
                                    color: function() {
                                        return 'rgb(' +
                                            Math.round(Math.random() * 255) +
                                            ', ' + Math.round(Math.random() * 255) +
                                            ', ' + Math.round(Math.random() * 255) + ')'
                                    }
                                }
                            },
                            left: 'center',
                            top: 'center',
                            // width: '96%',
                            // height: '100%',
                            right: null,
                            bottom: null,
                        }]
                    };

                    // 使用配置项绘制词云图
                    var chart1 = echarts.init(document.getElementById('wordcloud1'));
                    chart1.setOption(option1);
                }

                // 监听下拉菜单的变化，根据选择的年份和月份生成对应的词云图
                var yearSelect1 = document.getElementById('yearSelect1');
                var monthSelect1 = document.getElementById('monthSelect1');
                yearSelect1.addEventListener('change', updateWordCloud1);
                monthSelect1.addEventListener('change', updateWordCloud1);

                // 更新词云图
                function updateWordCloud1() {
                    var selectedYear1 = parseInt(yearSelect1.value);
                    var selectedMonth1 = parseInt(monthSelect1.value);
                    generateWordCloud1(selectedYear1, selectedMonth1);
                }

                // 初始生成默认年份和月份的词云图
                var defaultYear1 = parseInt(yearSelect1.value);
                var defaultMonth1 = parseInt(monthSelect1.value);
                // var defaultYear = parseInt({{.InitYear}});
                // var defaultMonth = parseInt({{.InitMonth}});
                generateWordCloud1(defaultYear1, defaultMonth1);
            </script>

        </div>
    </div>

    <div class="section" id="BusFactor">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong>bus_factor (detail):</strong></h2>
        <div id="chart2">
            <!-- 可视化图表将在这里插入 -->
            <div class="select" style="margin-right:20px; margin-top:20px; position:fixed; right:20px;"></div>

            <!-- 创建一个并排放置年份和月份按钮的容器 -->
            <div class="select-container-inline">
                <!-- 创建一个居中且美化的下拉菜单用于选择年份 -->
                <div class="select-container">
                    <select id="yearSelect2" class="custom-select">
                        {{range $value := .Years}}
                        <option value="{{$value}}">{{$value}}</option>
                        {{end}}
                    </select>
                </div>

                <!-- 创建一个居中且美化的下拉菜单用于选择月份 -->
                <div class="select-container">
                    <select id="monthSelect2" class="custom-select">
                        <option value="1">January</option>
                        <option value="2">February</option>
                        <option value="3">March</option>
                        <option value="4">April</option>
                        <option value="5">May</option>
                        <option value="6">June</option>
                        <option value="7">July</option>
                        <option value="8">August</option>
                        <option value="9">September</option>
                        <option value="10">October</option>
                        <option value="11">November</option>
                        <option value="12">December</option>
                    </select>
                </div>
            </div>
            <div class="item" id="wordcloud2" style="width:1200px;height:600px;"></div>


            <script>
                // JavaScript 部分代码
                // 获取数据
                var yearMonthData2 = {{
                .BusFactorDetailData
                }};

                if (yearMonthData2) {
                    document.getElementById("BusFactor").style.display = "block";
                } else {
                    document.getElementById("BusFactor").style.display = "none";
                }


                document.getElementById("yearSelect2").value = {{.InitYear}};
                document.getElementById("monthSelect2").value = {{.InitMonth}};

                // 生成词云图函数
                function generateWordCloud2(year, month) {
                    // 根据年份和月份获取相应的词频数据
                    var selectedData2 = [];
                    for (var i = 0; i < yearMonthData2.length; i++) {
                        if (yearMonthData2[i].Year === year && yearMonthData2[i].Month === month) {
                            selectedData2 = yearMonthData2[i].Data;
                            break;
                        }
                    }

                    // 将词频数据转换为 ECharts 所需的格式
                    var chartData2 = selectedData2.map(function (item) {
                        return {
                            name: item.Name,
                            value: item.Value
                        };
                    });

                    // 配置词云图的选项
                    var option2 = {
                        series: [{
                            type: 'wordCloud',
                            data: chartData2,
                            rotationRange: [-45, 0, 45, 90],
                            textStyle: {
                                normal: {
                                    color: function() {
                                        return 'rgb(' +
                                            Math.round(Math.random() * 255) +
                                            ', ' + Math.round(Math.random() * 255) +
                                            ', ' + Math.round(Math.random() * 255) + ')'
                                    }
                                }
                            },
                            left: 'center',
                            top: 'center',
                            // width: '96%',
                            // height: '100%',
                            right: null,
                            bottom: null,
                        }]
                    };

                    // 使用配置项绘制词云图
                    var chart2 = echarts.init(document.getElementById('wordcloud2'));
                    chart2.setOption(option2);
                }

                // 监听下拉菜单的变化，根据选择的年份和月份生成对应的词云图
                var yearSelect2 = document.getElementById('yearSelect2');
                var monthSelect2 = document.getElementById('monthSelect2');
                yearSelect2.addEventListener('change', updateWordCloud2);
                monthSelect2.addEventListener('change', updateWordCloud2);

                // 更新词云图
                function updateWordCloud2() {
                    var selectedYear2 = parseInt(yearSelect2.value);
                    var selectedMonth2 = parseInt(monthSelect2.value);
                    generateWordCloud2(selectedYear2, selectedMonth2);
                }

                // 初始生成默认年份和月份的词云图
                var defaultYear2 = parseInt(yearSelect2.value);
                var defaultMonth2 = parseInt(monthSelect2.value);

                generateWordCloud2(defaultYear2, defaultMonth2);
            </script>

        </div>
    </div>


    <div class="section" id="NewContributors">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong>new_contributors (detail)：</strong></h2>
        <div id="chart3">
            <!-- 可视化图表将在这里插入 -->
            <div class="select" style="margin-right:20px; margin-top:20px; position:fixed; right:20px;"></div>

            <!-- 创建一个并排放置年份和月份按钮的容器 -->
            <div class="select-container-inline">
                <!-- 创建一个居中且美化的下拉菜单用于选择年份 -->
                <div class="select-container">
                    <select id="yearSelect3" class="custom-select">
                        {{range $value := .Years}}
                        <option value="{{$value}}">{{$value}}</option>
                        {{end}}
                    </select>
                </div>

                <!-- 创建一个居中且美化的下拉菜单用于选择月份 -->
                <div class="select-container">
                    <select id="monthSelect3" class="custom-select">
                        <option value="1">January</option>
                        <option value="2">February</option>
                        <option value="3">March</option>
                        <option value="4">April</option>
                        <option value="5">May</option>
                        <option value="6">June</option>
                        <option value="7">July</option>
                        <option value="8">August</option>
                        <option value="9">September</option>
                        <option value="10">October</option>
                        <option value="11">November</option>
                        <option value="12">December</option>
                    </select>
                </div>
            </div>
            <div class="item" id="wordcloud3" style="width:1200px;height:600px;"></div>


            <script>
                // JavaScript 部分代码
                // 获取数据
                var yearMonthData3 = {{
                .NewContributorsDetailData
                }};


                if (yearMonthData3) {
                    document.getElementById("NewContributors").style.display = "block";
                } else {
                    document.getElementById("NewContributors").style.display = "none";
                }

                document.getElementById("yearSelect3").value = {{.InitYear}};
                document.getElementById("monthSelect3").value = {{.InitMonth}};

                // 生成词云图函数
                function generateWordCloud3(year, month) {
                    // 根据年份和月份获取相应的词频数据
                    var selectedData3 = [];
                    for (var i = 0; i < yearMonthData3.length; i++) {
                        if (yearMonthData3[i].Year === year && yearMonthData3[i].Month === month) {
                            selectedData3 = yearMonthData3[i].Data;
                            break;
                        }
                    }

                    // 将词频数据转换为 ECharts 所需的格式
                    var chartData3 = selectedData3.map(function (item) {
                        return {
                            name: item.Name,
                            value: item.Value
                        };
                    });

                    // 配置词云图的选项
                    var option3 = {
                        series: [{
                            type: 'wordCloud',
                            data: chartData3,
                            rotationRange: [-45, 0, 45, 90],
                            textStyle: {
                                normal: {
                                    color: function() {
                                        return 'rgb(' +
                                            Math.round(Math.random() * 255) +
                                            ', ' + Math.round(Math.random() * 255) +
                                            ', ' + Math.round(Math.random() * 255) + ')'
                                    }
                                }
                            },
                            left: 'center',
                            top: 'center',
                            // width: '96%',
                            // height: '100%',
                            right: null,
                            bottom: null,
                        }]
                    };

                    // 使用配置项绘制词云图
                    var chart3 = echarts.init(document.getElementById('wordcloud3'));
                    chart3.setOption(option3);
                }

                // 监听下拉菜单的变化，根据选择的年份和月份生成对应的词云图
                var yearSelect3 = document.getElementById('yearSelect3');
                var monthSelect3 = document.getElementById('monthSelect3');
                yearSelect3.addEventListener('change', updateWordCloud3);
                monthSelect3.addEventListener('change', updateWordCloud3);

                // 更新词云图
                function updateWordCloud3() {
                    var selectedYear3 = parseInt(yearSelect3.value);
                    var selectedMonth3 = parseInt(monthSelect3.value);
                    generateWordCloud3(selectedYear3, selectedMonth3);
                }

                // 初始生成默认年份和月份的词云图
                var defaultYear3 = parseInt(yearSelect3.value);
                var defaultMonth3 = parseInt(monthSelect3.value);

                generateWordCloud3(defaultYear3, defaultMonth3);
            </script>

        </div>
    </div>



    {{ range $key, $value := .QuantileStatsData }}
    <div class="section">
        <h2 style="color:rgb(0, 0, 0) ; font-size:40px"><strong>{{$key}} line race图 ：</strong></h2>
        <div id="chartRace">
            <!-- 可视化图表将在这里插入 -->
            <div class="select" style="margin-right:20px; margin-top:20px; position:fixed; right:20px;"></div>

            <div class="item" id="{{$key}}" style="width:1200px;height:600px;"></div>
            <script>
                var chartContainerRace = document.getElementById('{{$key}}');
                var chartRace = echarts.init(chartContainerRace);

                var optionRace = {
                    title: {
                        text: 'Line Race 图'
                    },
                    tooltip: {
                        trigger: 'axis', // 设置触发类型为轴
                        axisPointer: {
                            type: 'cross' // 启用十字准星指示器
                        }
                    },
                    legend: {
                        data: ['avg', 'quantile_0', 'quantile_1','quantile_2','quantile_3','quantile_4']
                    },
                    xAxis: {
                        type: 'category',
                        data: [{{range $value.RaceDates}}"{{ . }}", {{end}}]
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: 'avg',
                        type: 'line',
                        data: [{{range $value.Avg}}"{{ . }}", {{end}}],
                encode: {
                    x: 0, // 将数据的第一列映射到X轴
                        y: [1] // 将数据的第二列映射到Y轴
                }
                },
                {
                    name: 'quantile_0',
                        type: 'line',
                    data: [{{range $value.Quantile0}}"{{ . }}", {{end}}],
                    encode: {
                        x: 0, // 将数据的第一列映射到X轴
                            y: [1] // 将数据的第二列映射到Y轴
                    }
                },
                {
                    name: 'quantile_1',
                        type: 'line',
                    data: [{{range $value.Quantile1}}"{{ . }}", {{end}}],
                    encode: {
                        x: 0, // 将数据的第一列映射到X轴
                            y: [1] // 将数据的第二列映射到Y轴
                    }
                },
                {
                    name: 'quantile_2',
                        type: 'line',
                    data: [{{range $value.Quantile2}}"{{ . }}", {{end}}],
                    encode: {
                        x: 0, // 将数据的第一列映射到X轴
                            y: [1] // 将数据的第二列映射到Y轴
                    }
                },
                {
                    name: 'quantile_3',
                        type: 'line',
                    data: [{{range $value.Quantile3}}"{{ . }}", {{end}}],
                    encode: {
                        x: 0, // 将数据的第一列映射到X轴
                            y: [1] // 将数据的第二列映射到Y轴
                    }
                },
                {
                    name: 'quantile_4',
                        type: 'line',
                    data: [{{range $value.Quantile4}}"{{ . }}", {{end}}],
                    encode: {
                        x: 0, // 将数据的第一列映射到X轴
                            y: [1] // 将数据的第二列映射到Y轴
                    }
                }
                ]
                };

                chartRace.setOption(optionRace);
            </script>
        </div>
    </div>
    {{ end }}
</div>


</body>
</html>




